#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <assert.h>
// #include <cstdlib>


using namespace std;

void split_string(vector<string>& vet_string, string need_pro_string, char seq) {
    int idx = 0;
    int i;
    for (i = 0; i < need_pro_string.length(); ++i) {
        if (need_pro_string[i] == seq) {
            vet_string.push_back(need_pro_string.substr(idx, i-idx));
            idx = i+1;
        }
    }
    vet_string.push_back(need_pro_string.substr(idx, i-idx));
    
    // for (char c:need_pro_string) {
    //     if (c == seq) {
    //         vet_string.push_back(need_pro_string.substr(idx, ))
    //     }
    // }
}

class Solutions
{
public:
    char* itoa(int value, char* result, int base) {
		// check that the base if valid
		if (base < 2 || base > 36) { *result = '\0'; return result; }

		char* ptr = result, *ptr1 = result, tmp_char;
		int tmp_value;

		do {
			tmp_value = value;
			value /= base;
			*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
		} while ( value );

		// Apply negative sign
		if (tmp_value < 0) *ptr++ = '-';
		*ptr-- = '\0';
		while(ptr1 < ptr) {
			tmp_char = *ptr;
			*ptr--= *ptr1;
			*ptr1++ = tmp_char;
		}
		return result;
	}
    int check_sub(string& sub) {
        if (sub.length() > 1) {
            if (sub[0] == '0')
                return -1;
        }
        for (char c:sub) {
            if (c > '0' && c < '9' || (c>'a' && c < 'z')) {
                continue;
            } else {
                return -1;
            }
        }
        return 0;
    }
    string N_base_sub(string& N_base, string& sub1, string& sub2) {
        //check N base
        int base = stoi(N_base);
        if (base < 2 || base > 35) {
            return "-1";
        }

        // check sub1 and sub2
        if (check_sub(sub1) || check_sub(sub2)) {
            return "-1";
        }

        int sub_i1 = stoi(sub1, 0, base);
        int sub_i2 = stoi(sub2, 0, base);

        char buf[100];
        string ret = (sub_i1 > sub_i2)?"0":"1";

        // GCC编译器不支持 itoa函数，需要自定义实现！！！！
        itoa(abs(sub_i1-sub_i2), buf, base);
        return ret + " " + string(buf); 
    }
};



int main() {
    // parse input
    string input;
    
    // cin对象的使用需要注意！！


    // cin >> input;
    vector<string> args;
    // split_string(args, input, ' ');
    // while (!cin.eof()) {
    //     cin >> input;
    //     args.push_back(input);
    // }
    for (int i = 0; i < 3; ++i ) {
        cin >> input;
        args.push_back(input);
        cout << cin.peek() << endl;
    }
    cout << cin.flags() << endl;
    // while(cin >> input) {
    //     args.push_back(input);
    // }
    assert(args.size() == 3);

    // handle N sub
    Solutions s;
    cout << s.N_base_sub(args[0], args[1], args[2]);
}